from math import sin, cos, pi
from matplotlib import pyplot as plt
from typing import Callable, Iterable


def _draw1(func_x: Callable[[float], float], func_y: Callable[[float], float], theta: Iterable[float]):
    theta = list(theta)
    plt.plot([func_x(v) for v in theta], [func_y(v) for v in theta], color="r")


def _draw2(func: Callable[[float], float], theta: Iterable[float]):
    theta = list(theta)
    plt.polar(theta, [func(v) for v in theta])


a = 1

plt.subplot(121)
_draw1(lambda t: a * (1 - sin(t)) * cos(t),
       lambda t: a * (1 - sin(t)) * sin(t),
       (t / 10 for t in range(0, int(2 * pi * 10) + 2, 1)))
plt.title("心形曲线-直角坐标系")

plt.subplot(122, projection="polar")
_draw2(lambda t: a * (1 - sin(t)),
       (t / 10 for t in range(0, int(2 * pi * 10) + 2, 1)))


plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.show()
